package com.lanju.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;

import com.lanju.entity.HouseHold;
import com.lanju.entity.SystemAdmin;

@Repository
public class HouseHoldDao {
	
    private static final Log log = LogFactory.getLog(HouseHoldDao.class);
    @PersistenceContext(unitName = "financialmarketingUnit")
	private EntityManager entityManager;
    
	public int saveHouseHold(SystemAdmin systemAdmin){
		
		return 0;
	}

	public SystemAdmin getSystemAdmin(Integer id){
		try {
			SystemAdmin systemAdmin=entityManager.find(SystemAdmin.class, id);
			return systemAdmin;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public HouseHold getHouseHoldDetail(Integer id){
		try {
			HouseHold h=entityManager.find(HouseHold.class, id);
			return h;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public List<HouseHold> getHouseHoldList(){
		StringBuffer sql=new StringBuffer();
		sql.append("from HouseHold");
		Query query=entityManager.createQuery(sql.toString());
		List<HouseHold> h=query.getResultList();
		return h;
	}
	
	public HouseHold getHouseHoldListByPhone(String phone){
		StringBuffer sql=new StringBuffer();
		sql.append("from HouseHold where phone='"+phone+"'");
		Query query=entityManager.createQuery(sql.toString());
		HouseHold h=(HouseHold) query.getSingleResult();
		return h;
	}
	
}
